N = int(1e5 + 5) 
f = [0 for i in range(0, N)]
s = input()
ss = [0 for i in range(0, N)]
ans = 0
idx = 0
L = len(s)
for i in range(0, L):
	ss[i + 1] = s[i]

for i in range(2, L+1):
	if(ss[i] == '(' or ss[i] == '[') :
		continue
	if ss[i] == ')' and ss[i - 1 - f[i-1]] == '(':
		f[i] = f[i-1] + 2 + f[i - 2 - f[i-1]]
	if ss[i] == ']' and ss[i - 1 - f[i-1]] == '[':
		f[i] = f[i-1] + 2 + f[i - 2 - f[i-1]]
	if f[i] > ans:
		ans = f[i]
		idx = i
print(ans)